<?php
namespace other\orders;
use other\ShopingConn;
use other\Table;

/**
 * 修改订单的dhour值
 */
class Dtime
{
    /**
     * 处理    Abnormal
     * @return void
     * @throws \think\Exception
     */
    public function do()
    {
        // order 表的美国时区时间  和  表的中国时区时间
        ShopingConn::getConn()->table(Table::Table_Order)
            ->field("id,DATE_FORMAT(FROM_UNIXTIME(orders.created_at-57600), '%y%m%d') AS date_u,
            DATE_FORMAT(FROM_UNIXTIME(orders.created_at), '%y%m%d') AS date_c")
            ->where('date_usa',0)
            ->where('created_at','>',0)
            ->chunk(5000,function ($datas){
                if ($datas){
                    foreach ($datas as $data){

                        $id = $data['id'];
                        $date_usa = $data['date_u'];
                        $date_cn = $data['date_c'];

                        if ($date_usa){
                            ShopingConn::getConn()->table(Table::Table_Order)
                                ->where('id',$id)->update(compact("date_usa","date_cn"));
                        }
                    }
                }
            });
    }
}
